<?php
/**
 * User: root
 * Date: 13-11-9
 * Time: 上午7:49
 */

class Bus_model extends CI_Model {
    function __construct(){
        parent::__construct();
        $this->load->database();
    }

    /**
     * 根据路线名搜索路线
     * @param $linename
     * @return Array
     */
    function SearchByLinename($linename){
        $this->db->like('bLineName',$linename);
        return $this->db->get('t_bus')->result();
    }
    function GetLineStations($lineid){
        $this->db->where('bBusid',$lineid);
        return $this->db->get('t_station')->result();
    }

    /**
     * 列表显示所有的路线
     * @param $offset
     * @param $count
     * @return mixed
     */
    function ListAllLine($offset,$count){
        $this->db->limit($count,$offset);
        return $this->db->get('t_bus')->result();
    }

    /**
     * 所有路线的数量
     * @return int
     */
    function GetLineCount(){
        $this->db->select('count(1) as c',false);
        return $this->db->get('t_bus')->row()->c;
    }

    /**
     * @param $station_name
     * @return mixed
     */
    function GetLinesByStation($station_name){
        $sql = "select * from t_bus where bBusid in (select bBusid from t_station where sName like '%".$station_name."%' )";
        return $this->db->query($sql)->result();
    }


}